package com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.Impl;
import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.ShowDao;
import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.entity.ShowEntity;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ShowDaoImpl implements ShowDao {
    public List<ShowEntity> queryInformation() throws Exception {
        Connection connection = DBUtils.getCon();
        List<ShowEntity> InformationList = new ArrayList<>();
        String sql = "select leave_date,name,leave_class,adjust_date,adjust_class,reason,term,direction from adjust where YEARWEEK(date_format(leave_date,'%Y-%m-%d')) = YEARWEEK(now())";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            ShowEntity showEntity = new ShowEntity();
            showEntity.setLeave_date(resultSet.getString("leave_date"));
            showEntity.setLeave_class(resultSet.getString("leave_class"));
            showEntity.setAdjust_date(resultSet.getString("adjust_date"));
            showEntity.setAdjust_class(resultSet.getString("adjust_class"));
            showEntity.setReason(resultSet.getString("reason"));
            showEntity.setName(resultSet.getString("name"));
            showEntity.setTerm(resultSet.getString("term"));
            showEntity.setDirection(resultSet.getString("direction"));
            InformationList.add(showEntity);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}
